package com.example.springsecuritydemo.support;

import java.util.List;

/**
 * 分页组件
 * @author chenggang
 *
 * @param <T>
 */
public class PageResult<T> {
	// 每页存放的记录
	private List<T> list;
	// 第几页
	private Integer pageNo=1;
	//每页显示多少条记录
	private Integer pageSize =20;
	// 总共有多少条数据
	private Integer totalCount;
	//总共有多少页
	private Integer totalPage;
	
	
	private PageResult() {
		
	}
	
	public static <T> PageResult<T> create(Integer pageNo,Integer pageSize,Integer totalCount,List<T> data) {
		PageResult<T> result = new PageResult<T>();
		result.setPageNo(pageNo);
		result.setPageSize(pageSize);
		result.setList(data);
		result.setTotalCount(totalCount);
		return result;
	}
	
	private PageResult(Integer pageNo,Integer pageSize) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}
	
	

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = (totalCount==null)?0:totalCount;
		this.totalPage =(totalCount%pageSize)==0?(totalCount/pageSize): (totalCount / pageSize) + 1;
	}

	public Integer getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	
}
